import axios from 'axios'
export default {
  namespaced: true,
  state: {
    // token: localStorage.getItem('token') || ''
    token: '',
    userInfo: {}
  },
  mutations: {
    // updataToken (state, newToken) {
    //   state.token = newToken
    //   localStorage.setItem('token', newToken)
    // }
    updataToken (state, newToken) {
      state.token = newToken
    },

    updataUserInfo (state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {

    async  getUserInfo (context) {
      // 发送请求获取用户信息
      // 这里的this指向store,所以不能使用this
      // this.$http.get('/my/userinfo')

      const { data: res } = await axios.get('/my/userinfo')
      if (res.code !== 0) return
      context.commit('updataUserInfo', res.data)
    }
  },
  getters: {

  }
}
